home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 8.4 KB | 330 lines | [TEXT/KAHL] |
- /***************************************************** IMPLEMENTATION
- DATE: 9/22/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPVisualObject
-
- SUPERCLASS: CPPObject
-
- This is an abstract C++ superclass for objects which live in
- windows.
-
- ********************************************************************/
-
- #include <CPPVisualObject.h>
- #include <CPPWindow.h>
- #include <Commands.h>
-
- Rect kEmptyRect = {-1, -1, -1, -1};
- Rect kDefaultRect = {0, 0, 10, 10};
- RGBColor RGBBlack = {0, 0, 0},
- RGBWhite = {65535, 65535, 65535},
- RGBRed = {65535, 0, 0},
- RGBGreen = {0, 65535, 0},
- RGBBlue = {0, 0, 65535};
-
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPVisualObject::CPPVisualObject (CPPWindow *itsWindow, Rect *itsBounds,
- Boolean canBeTarget,
- Boolean active, Boolean visible)
- {
- if (itsWindow)
- {
- this->owningWObject = itsWindow;
- this->owningWindow = itsWindow->GetWindow();
- this->isActive = active;
- this->isVisible = visible;
- this->bounds = *itsBounds;
- this->canBeTarget = canBeTarget;
- this->isTarget = 0;
- this->doClickProc = NULL;
- this->commandEquivalent = kNoCommand;
- // tell the window it is responsible for feeding us
- itsWindow->StartManagingObject(this);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPVisualObject::~CPPVisualObject (void)
- {
- // tell the window it doesn't have to worry about us anymore
- if (owningWObject)
- owningWObject->StopManagingObject(this);
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPVisualObject::ClassName (void)
- {
- return "CVisualObject";
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::InColorWindow (void)
- /* return TRUE if we live in a color window */
- {
- if (this->owningWObject)
- return this->owningWObject->IsColorWindow();
- else
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::DoCommand (short commandID)
- /* do a command associated with a menu */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::Draw (void)
- /* method for drawing an object */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::DoIdle (void)
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::SetCommand (short theCommand)
- {
- this->commandEquivalent = theCommand;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::SetDoClickProc (ClickProcPtr clickProc)
- {
- this->doClickProc = clickProc;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::DoClick (EventRecord *theEvent)
- /* SUBCLASS SHOULD OVERRIDE */
- {
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::DoKey (char theKey, short modifiers, short what)
- /* SUBCLASS SHOULD OVERRIDE */
- {
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::Move (short newH, short newV)
- /* move the entire object to a new position */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- RgnHandle OldBoundsRgn = NewRgn(),
- NewBoundsRgn = NewRgn();
-
- // remember where we were
- RectRgn(OldBoundsRgn, GetBounds());
-
- if (this->isTarget)
- EraseHilite();
-
- // call the virtual method to move us
- MoveContent (newH, newV);
-
- // find out where we are
- RectRgn(NewBoundsRgn, GetBounds());
-
- // erase and invalidate the XOR of the two regions
- XorRgn (OldBoundsRgn, NewBoundsRgn, NewBoundsRgn);
- EraseRgn (NewBoundsRgn);
- InvalRgn (NewBoundsRgn);
-
- if (this->isTarget)
- DrawHilite();
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::Resize (short newWidth, short newHeight)
- /* change the width and height of an object */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- RgnHandle OldBoundsRgn = NewRgn(),
- NewBoundsRgn = NewRgn();
-
- // remember where we were
- RectRgn(OldBoundsRgn, GetBounds());
-
- if (this->isTarget)
- EraseHilite();
-
- // call the virtual method to move us
- ResizeContent(newWidth, newHeight);
-
- // find out where we are
- RectRgn(NewBoundsRgn, GetBounds());
-
- // erase and invalidate the changed region
- UnionRgn(NewBoundsRgn, OldBoundsRgn, NewBoundsRgn);
- EraseRgn (NewBoundsRgn);
- InvalRgn (NewBoundsRgn);
-
- if (this->isTarget)
- DrawHilite();
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::Global2Local (Point *thePoint)
- /* convert a point from global coordinates to local coordinates */
- /* regardless of whether the port is set to our window or not */
- {
- GrafPtr savePort;
-
- GetPort (&savePort);
- if (savePort != this->owningWindow)
- {
- SetPort (this->owningWindow);
- GlobalToLocal (thePoint);
- SetPort (savePort);
- }
- else
- GlobalToLocal(thePoint);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::TargetHilite (Boolean makeTarget)
- /* change the hiliteed state of the object (some objects, like */
- /* lists, have different appearances when they are the target) */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- this->isTarget = makeTarget;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::DrawHilite (void)
- /* Draw the hilite around an object, indicating it is the target */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::EraseHilite (void)
- /* Remove the hilite around an object, indicating it is the target */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::MakeVisible (Boolean nowVisible)
- /* do the bookkeeping to record that we are now (in)visible */
- /* SUBCLASS MAY OVERRIDE */
- {
- this->isVisible = nowVisible;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::Activate (Boolean nowActive)
- /* do the bookkeeping to record that we are now (in)active */
- {
- this->isActive = nowActive;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::InContent(Point clickPt)
- /* return TRUE if the point (in global coordinates) is */
- /* inside the object */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- Point myPoint = clickPt;
-
- if (this->isVisible)
- {
- Global2Local (&myPoint);
- return PtInRect (myPoint, GetBounds());
- }
- else
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- Rect *CPPVisualObject::GetBounds (void)
- /* return the boundsrect of the object */
- /* SUBCLASS MUST OVERRIDE */
- {
- return &kEmptyRect;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::IsActive (void)
- /* return whether the object is active or inactive */
- /* SUBCLASS MAY OVERRIDE */
- {
- return this->isActive;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::IsVisible (void)
- /* return whether the object is visible or invisible */
- {
- return this->isVisible;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPVisualObject::CanBeMadeTarget (void)
- /* return whether the object can be made the target of the window */
- {
- return this->canBeTarget;
- }
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::MoveContent (short newH, short newV)
- /* move the contents of the object to a new position */
- /* SUBCLASS MUST OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPVisualObject::ResizeContent (short newWidth, short newHeight)
- /* change the size of the contents of the object */
- /* SUBCLASS MUST OVERRIDE */
- {
-
- }
-